package com.dididoctor.doctor.Activity.Order.Inquiry;

import android.graphics.Bitmap;
import android.view.View;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.dididoctor.doctor.MV.EduActivity;
import com.dididoctor.doctor.R;
import com.dididoctor.doctor.Utils.LoaderImage;
import com.dididoctor.doctor.Utils.UserHeadImage;
import com.nostra13.universalimageloader.core.assist.FailReason;
import com.nostra13.universalimageloader.core.listener.ImageLoadingListener;

import java.util.List;

/**
 * Created by liying on 2016/4/26.
 */
public class InquiryDetailsActivity extends EduActivity implements InquiryDetailsView {
    private ImageView mIvHead, mIvGender;
    private TextView mTvName, mTvAge, mTvDisease;
    private LoaderImage loaderImage;
    private ListView mLvQuestion;
    private InquiryAdapter mAdapter;
    private InquiryDetailsPresenter mPresenter;
    private String recId;
    private String patientName;
    private String age;
    private String illName;
    private String patientHeadPic;
    private String sex;
    private UserHeadImage mImgUserimg;
    @Override
    public void init() {
        recId= getIntent().getStringExtra("recId");
        patientName= getIntent().getStringExtra("patientName");
        age= getIntent().getStringExtra("age");
        illName= getIntent().getStringExtra("illName");
        patientHeadPic = getIntent().getStringExtra("patientHeadPic");
        sex = getIntent().getStringExtra("sex");
        initView();
    }

    @Override
    public void onClickEvent(View view) {

    }

    @Override
    public void setContentLayout() {
        setContentView(R.layout.activity_inquirydetails);
    }

    public void initView() {
        ((TextView) findViewById(R.id.tv_title)).setText("问诊表详情");
        mImgUserimg = (UserHeadImage) findViewById(R.id.img_userimg);
        mIvGender = (ImageView) findViewById(R.id.iv_gender);
        if ("0".equals(sex)){
            mIvGender.setImageResource(R.drawable.icon_girl);
        }else{
            mIvGender.setImageResource(R.drawable.icon_boy);
        }
        mTvName = (TextView) findViewById(R.id.tv_name);
        mTvAge = (TextView) findViewById(R.id.tv_age);
        mTvDisease = (TextView) findViewById(R.id.tv_disease);
        mLvQuestion = (ListView) findViewById(R.id.lv_question);

        mTvName.setText(patientName);
        mTvAge.setText(age);
        mTvDisease.setText(illName);

        loaderImage = new LoaderImage(InquiryDetailsActivity.this);
        loaderImage.load(mImgUserimg, patientHeadPic, new ImageLoadingListener() {
            @Override
            public void onLoadingStarted(String s, View view) {
                mImgUserimg.setImageResource(R.drawable.img_doctordefault);
            }

            @Override
            public void onLoadingFailed(String s, View view, FailReason failReason) {
                mImgUserimg.setImageResource(R.drawable.img_doctordefault);
            }

            @Override
            public void onLoadingComplete(String s, View view, Bitmap bitmap) {

            }

            @Override
            public void onLoadingCancelled(String s, View view) {

            }
        });
        mPresenter = new InquiryDetailsPresenter(InquiryDetailsActivity.this, InquiryDetailsActivity.this);
        mPresenter.getInquiryDetails(recId);
    }

    @Override
    public void fillData(List<InquiryBean> data) {
        mAdapter = new InquiryAdapter(InquiryDetailsActivity.this, data);
        mLvQuestion.setAdapter(mAdapter);
    }

    @Override
    public void getDataFail() {
        showToastMessage("获取问诊表信息失败");
        InquiryDetailsActivity.this.finish();

    }
}
